/**
 * 
 */
package com.sci.web.action.eninfomanager;

import java.io.UnsupportedEncodingException;

import javax.annotation.Resource;

import com.sci.web.action.util.BaseAction;
import com.sci.web.dao.EnterpriseInfoManageDao;

/**
 * @author BaiFuyou
 * @date: Oct 28, 2011 10:50:24 PM
 */
public class GetEnterpriseInfoByUserRoleReloadAction extends BaseAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = -2477198032250868447L;
	@Resource
	private EnterpriseInfoManageDao enterpriseInfoManageDao;
	/**
	 * 企业名称
	 */
	private String name;
	/**
	 * 经济类型
	 */
	private int eco_type;
	/**
	 * 城市
	 */
	private int city;
	/**
	 * 科技类型企业类别
	 */
	private int science_type;
	/**
	 * 所属国民经济行业
	 */
	private int gdp;
	/**
	 * 组织类型
	 */
	private int org_type;
	/**
	 * 1为审核 2未通过 3 通过审核
	 */
	private int flag;

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name
	 *            the name to set
	 * @throws UnsupportedEncodingException 
	 */
	public void setName(String name) throws UnsupportedEncodingException {
		
		this.name = java.net.URLDecoder.decode(name,"utf-8");
	}

	/**
	 * @return the eco_type
	 */
	public int getEco_type() {
		return eco_type;
	}

	/**
	 * @param eco_type
	 *            the eco_type to set
	 */
	public void setEco_type(int eco_type) {
		this.eco_type = eco_type;
	}

	/**
	 * @return the city
	 */
	public int getCity() {
		return city;
	}

	/**
	 * @param city
	 *            the city to set
	 */
	public void setCity(int city) {
		this.city = city;
	}

	/**
	 * @return the science_type
	 */
	public int getScience_type() {
		return science_type;
	}

	/**
	 * @param science_type
	 *            the science_type to set
	 */
	public void setScience_type(int science_type) {
		this.science_type = science_type;
	}

	/**
	 * @return the gdp
	 */
	public int getGdp() {
		return gdp;
	}

	/**
	 * @param gdp
	 *            the gdp to set
	 */
	public void setGdp(int gdp) {
		this.gdp = gdp;
	}

	/**
	 * @return the org_type
	 */
	public int getOrg_type() {
		return org_type;
	}

	/**
	 * @param org_type
	 *            the org_type to set
	 */
	public void setOrg_type(int org_type) {
		this.org_type = org_type;
	}

	/**
	 * @return the flag
	 */
	public int getFlag() {
		return flag;
	}

	/**
	 * @param flag
	 *            the flag to set
	 */
	public void setFlag(int flag) {
		this.flag = flag;
	}

	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		StringBuffer sb = new StringBuffer("");
		System.out.println(flag +"  ===flag");
		String sql = "";
		if(flag == 1){
			sb.append("select enterprise_url,enterprise_pic,id, user_id, editable,enterprise_state," +
					" enterprise_style,enterprise_expe_year, enterprise_demo_year,enterprise_is_nationalInnovation,enterprise_updateinfo," +
					"enterprise_updatestatus, enterprise_name,enterprise_address,enterprise_corporate_code, enterprise_city,enterprise_postcode," +
					"enterprise_corporateRepresentative,enterprise_telephone,enterprise_person_incharge,enterprise_phone_incharge," +
					"enterprise_eco_type, enterprise_org_type,enterprise_largest_sharehoder,enterprise_largest_share,enterprise_listed_type," +
					"enterprise_science_type,enterprise_industry_code,enterprise_highsci_authenticate_year," +
					"enterprise_highsci_authenticate_department,enterprise_highsci_field,enterprise_credit_degree,enterprise_business_field," +
					"enterprise_field_closeness,enterprise_major_business,enterprise_staff_count,enterprise_staff_collegedegree_count," +
					"enterprise_research_staff_count,enterprise_senior_technician_count, 1 as isCheck from enterprise_base where enterprise_base.user_id in (select user.user_id from user where user_role = 5 and user_state=5) and enterprise_base.enterprise_city = '"+city+"' ");			
			if (!name.equals("-1")) {
				sql = "and enterprise_name like '%" + name + "%' ";
			} else {
				sql = " ";
			}
			if (eco_type != 0) {
				sql += (" and enterprise_eco_type=" + eco_type + "  ");
			}else{
				sql +="  ";
			}
			if (city != 0) {
				sql += ("and enterprise_city=" + city + "  ");
			}else{
				sql +="  ";
			}
			if (gdp != 0) {
				sql += (" and enterprise_industry_code=" + gdp + "  ");
			}else{
				sql +="  ";
			}
			if (org_type != 0) {
				sql += (" and enterprise_industry_code=" + org_type + "  ");
			}else{
				sql +="  ";
			}
			if (science_type != 0) {
				sql += (" and enterprise_science_type =" + science_type + " ");
			}else{
				sql +="  ";
			}
			if (sql.trim().endsWith("and")) {
				sql = sql.trim().substring(0, sql.length() - 3);
			}
		}
		if(flag == 2){
			sb.append("select enterprise_url,enterprise_pic,id, user_id, editable,enterprise_state," +
					" enterprise_style,enterprise_expe_year, enterprise_demo_year,enterprise_is_nationalInnovation,enterprise_updateinfo," +
					"enterprise_updatestatus, enterprise_name,enterprise_address,enterprise_corporate_code, enterprise_city,enterprise_postcode," +
					"enterprise_corporateRepresentative,enterprise_telephone,enterprise_person_incharge,enterprise_phone_incharge," +
					"enterprise_eco_type, enterprise_org_type,enterprise_largest_sharehoder,enterprise_largest_share,enterprise_listed_type," +
					"enterprise_science_type,enterprise_industry_code,enterprise_highsci_authenticate_year," +
					"enterprise_highsci_authenticate_department,enterprise_highsci_field,enterprise_credit_degree,enterprise_business_field," +
					"enterprise_field_closeness,enterprise_major_business,enterprise_staff_count,enterprise_staff_collegedegree_count," +
					"enterprise_research_staff_count,enterprise_senior_technician_count, 1 as isCheck from enterprise_base where enterprise_base.user_id in (select user.user_id from user where user_role = 4 and user_state=0) and enterprise_base.enterprise_city = '"+city+"' ");			
			if (!name.equals("-1")) {
				sql = "and enterprise_name like '%" + name + "%' ";
			} else {
				sql = " ";
			}
			if (eco_type != 0) {
				sql += (" and enterprise_eco_type=" + eco_type + "  ");
			}else{
				sql +="  ";
			}
			if (city != 0) {
				sql += ("and enterprise_city=" + city + "  ");
			}else{
				sql +="  ";
			}
			if (gdp != 0) {
				sql += (" and enterprise_industry_code=" + gdp + "  ");
			}else{
				sql +="  ";
			}
			if (org_type != 0) {
				sql += (" and enterprise_industry_code=" + org_type + "  ");
			}else{
				sql +="  ";
			}
			if (science_type != 0) {
				sql += (" and enterprise_science_type =" + science_type + " ");
			}else{
				sql +="  ";
			}
			if (sql.trim().endsWith("and")) {
				sql = sql.trim().substring(0, sql.length() - 3);
			}
		}
		if(flag == 3){
			sb.append("select enterprise_url,enterprise_pic,id, user_id, editable,enterprise_state," +
					" enterprise_style,enterprise_expe_year, enterprise_demo_year,enterprise_is_nationalInnovation,enterprise_updateinfo," +
					"enterprise_updatestatus, enterprise_name,enterprise_address,enterprise_corporate_code, enterprise_city,enterprise_postcode," +
					"enterprise_corporateRepresentative,enterprise_telephone,enterprise_person_incharge,enterprise_phone_incharge," +
					"enterprise_eco_type, enterprise_org_type,enterprise_largest_sharehoder,enterprise_largest_share,enterprise_listed_type," +
					"enterprise_science_type,enterprise_industry_code,enterprise_highsci_authenticate_year," +
					"enterprise_highsci_authenticate_department,enterprise_highsci_field,enterprise_credit_degree,enterprise_business_field," +
					"enterprise_field_closeness,enterprise_major_business,enterprise_staff_count,enterprise_staff_collegedegree_count," +
					"enterprise_research_staff_count,enterprise_senior_technician_count, 3 as isCheck from enterprise_base where enterprise_base.user_id in (select user.user_id from user where user_role in (3,4) and user_state=3) and enterprise_base.enterprise_city = "+city+" ");			
			if (!name.equals("-1")) {
				sql = "and enterprise_name like '%" + name + "%' ";
			} else {
				sql = " ";
			}
			if (eco_type != 0) {
				sql += (" and enterprise_eco_type=" + eco_type + "  ");
			}else{
				sql +="  ";
			}
			if (city != 0) {
				sql += ("and enterprise_city=" + city + "  ");
			}else{
				sql +="  ";
			}
			if (gdp != 0) {
				sql += (" and enterprise_industry_code=" + gdp + "  ");
			}else{
				sql +="  ";
			}
			if (org_type != 0) {
				sql += (" and enterprise_industry_code=" + org_type + "  ");
			}else{
				sql +="  ";
			}
			if (science_type != 0) {
				sql += (" and enterprise_science_type =" + science_type + " ");
			}else{
				sql +="  ";
			}
			if (sql.trim().endsWith("and")) {
				sql = sql.trim().substring(0, sql.length() - 3);
			}
		}
		sb.append(sql);
		String sql_ = sb.toString();
		System.out.println(sql_);
		super.setContentType(super.JSON);
		super.outPrint(super.getJSONArrayString(enterpriseInfoManageDao.getEnterprsieBase_reload(sql_)));
		return "json";
	}
}
